package com.cust.cow.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cust.cow.common.CattleAddress;
import com.cust.cow.common.Result;
import com.cust.cow.pojo.breed;
import com.cust.cow.pojo.cattle;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Mapper
public interface CattleMapper extends BaseMapper<cattle> {
    @Select("select * from cattle")
    public List<cattle> findCattleAll();

    @Select("select * from cattle where cattle_id = #{cattleId}")
    public cattle findCattleById(Integer cattleId);

    /**
     *
     * @param cattle
     * @return
     */
    @Insert("insert into cattle values(#{cattleId},#{breedId},#{birthday},#{weight},#{sex},#{quarantineSituation},#{remark})")
    public int insertCattle(@RequestBody cattle cattle);

    @Delete("delete from cattle where cattle_id = #{cattleId}")
    public int deleteCattle(Integer cattleId);

    @Select("select c.cattle_id, c.sex, ca.address from cattle c, cattle_address ca where c.cattle_id = ca.cattle_id")
    public List<CattleAddress> findCattleAddress();

    @Select("select c.cattle_id, c.sex, ca.address from cattle c, cattle_address ca where c.cattle_id = ca.cattle_id and c.cattle_id = #{cattleId}")
    public CattleAddress findCattleAddressById(Integer cattleId);
}
